﻿
using DomainModel.Domain.Model.MessageTypeModel;
using DomainModel.Utils;
using NHibernate;
using NHibernate.Criterion;

namespace DomainModel.Infrastructure.Persistence
{
    public class MessageTypesRepository : BaseRepository<MessageType, MessageTypeId>, IMessageTypesRepository
    {
        public MessageTypesRepository(ISession session, IApplicationConfig applicationConfig)
            : base(session, applicationConfig)
        {
        }

        public MessageType Get(string hash)
        {
            return Session.CreateCriteria(typeof(MessageType))
               .Add(Restrictions.Eq("Hash", hash))
               .UniqueResult<MessageType>();
        }

        public MessageTypeId NextMessageTypeId()
        {
            return new MessageTypeId(NextIntFromSeq());
        }
    }
}